package com.paw.dogs.sky.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lvzihai
 * @date 2021/6/16
 **/
@Slf4j
@RestController
public class SkyController {

  @Value("${spring.application.name:sky-service}")
  private String applicationName;

  @Value("${server.port:8080}")
  private Integer serverPort;

  @GetMapping("/sky")
  public String sky (@RequestParam(required = false) String name) {
    String msg = "this is " + applicationName + " port " + serverPort + " Time: " + DateUtil.now();
    if (StrUtil.isNotEmpty(name)) {
      msg = msg + " name: " + name;
    }
    log.info(msg);
    return msg;
  }

  @PostMapping("/deliver")
  public String deliver (String packageBox) {
    String msg = "this is " + applicationName + " port " + serverPort + " Time: " + DateUtil.now();
    String result = msg + " delivered packageBox: " + packageBox;
    log.info(result);
    return result;
  }


  @PostMapping("/feignPost")
  public String feignPost(@RequestParam(name = "name") String name){
    String msg = "this is feignPost" + applicationName + " port " + serverPort + " Time: " + DateUtil.now();
    if (StrUtil.isNotEmpty(name)) {
      msg = msg + " name: " + name;
    }
    log.info(msg);
    return msg;
  }


  @PostMapping("/feignBody")
  public String feignBody(@RequestBody String name){
    String msg = "this is feignPost" + applicationName + " port " + serverPort + " Time: " + DateUtil.now();
    if (StrUtil.isNotEmpty(name)) {
      msg = msg + " name: " + name;
    }
    log.info(msg);
    return msg;
  }


  @PostMapping("/feignParamWithBody")
  public String feignParamWithBody(@RequestParam("str1") String str1,@RequestBody String body){
    String msg = str1+" " + body;
    log.info(msg);
    return msg;
  }


}
